package com.web.security.provider;

import com.web.security.token.FrontAuthenticationToken;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2016/4/21
 * Time: 17:32
 * To change this template use File | Settings | File Templates.
 */

public class FrontAuthenticationProvider implements AuthenticationProvider {


    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        FrontAuthenticationToken authenticationToken = (FrontAuthenticationToken) authentication;
        String validateCode = authenticationToken.getValidateCode();
        System.out.println("--------------" + validateCode);
        authenticationToken.setAuthenticated(true);
        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
        return authenticationToken;
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return FrontAuthenticationToken.class.isAssignableFrom(authentication);
    }
}
